import Types from '../types'
import {apiUrl} from "../../../config";


/**
 * 用户登录
 *
 */
export function onLogin(params){
  return dispatch => {
    dispatch({type: Types.LOGIN_READY});
    let url = `${apiUrl}/app/login`;
    fetch(url, {
      method: "POST",
      headers: {
        'Content-Type': 'multipart/form-data',
      },
      body: params
    }).then(res => {
      console.log(res)
      return res.json();

      // dispatch({
      //   type: Types.LOGIN_SUCCESS,
      //   login: data,
      // })
      // console.log(res.json())
      // let data = res._bodyText;
      // data = JSON.parse(data)
      // console.log(data)
      // if(data.success){
      //   dispatch({
      //     type: Types.LOGIN_SUCCESS,
      //     login: data,
      //   })
      // }
    }).then((data) => {
      console.log(data)
      dispatch({
        type: Types.LOGIN_SUCCESS,
        login: data,
      })
    }).catch(error => {
      console.log(2)
      console.log(error)
      dispatch({
        type: Types.LOGIN_FAIL,
        error
      })
    })
  }
}
